var a = getApp();

module.exports = {
    data: {
        CategoryList: [],
        CategoryMap: {}
    },
    event: function(t, e, o, n, c) {
        wx.request({
            url: a.globalData.requestUrl + "/Imp.ashx",
            data: {
                adid: t,
                id: e,
                p1: o,
                p2: n,
                p3: c
            },
            header: a.globalData.header,
            success: function(a) {},
            fail: function(a) {},
            complete: function(a) {}
        });
    },
    getCategoryMap: function(t) {
        var e = this;
        wx.request({
            url: a.globalData.requestUrl + "/GetCategoryList.ashx",
            header: a.globalData.header,
            success: function(a) {
                var t = a.data.Data;
                if (t.length > 0) {
                    e.data.CategoryList = t;
                    for (var o = 0; o < t.length; o++) {
                        var n = t[o];
                        e.data.CategoryMap[n.Code] = n;
                    }
                }
            },
            fail: function(a) {},
            complete: function(a) {
                t && t(e.data.CategoryMap);
            }
        });
    },
    zan: function(t) {
        wx.request({
            url: a.globalData.requestUrl + "/Zan.ashx",
            data: {
                id: t
            },
            header: a.globalData.header,
            success: function(a) {},
            fail: function(a) {},
            complete: function(a) {}
        });
    },
    check_token: function(t) {
        wx.request({
            url: a.globalData.requestUrl + "/CheckToken.ashx",
            header: a.globalData.header,
            success: function(a) {
                t && t(a.data);
            },
            fail: function(a) {},
            complete: function(a) {}
        });
    },
    login: function(t) {
        var e = this, o = function(t) {
            wx.login({
                success: function(e) {
                    e.code ? wx.request({
                        url: a.globalData.requestUrl + "/login.ashx",
                        header: a.globalData.header,
                        data: {
                            jscode: e.code
                        },
                        success: function(e) {
                            a.globalData.header.p_t = e.data.Data.token, wx.setStorage({
                                key: "p_t",
                                data: a.globalData.header.p_t,
                                success: function() {},
                                fail: function(a) {}
                            }), t && t(e.data.Data.token);
                        },
                        fail: function(a) {
                            t && t(void 0, a);
                        },
                        complete: function(a) {}
                    }) : t && t(void 0, e.errMsg);
                }
            });
        };
        wx.checkSession({
            success: function() {
                a.globalData.header.p_t = wx.getStorageSync("p_t"), a.globalData.header.p_t ? e.check_token(function(e) {
                    1 != e.Result ? o(t) : t && t(a.globalData.header.p_t);
                }) : o(t);
            },
            fail: function() {
                o(t);
            }
        });
    }
};